/**
 * @param {number} num
 * @return {number}
*/
var addDigits = function(num) {
  function addDigit(n) {
    let str = n.toString(), result = 0;
    for(let i = 0; i < str.length; i++) {
      result += str[i].charCodeAt() - '0'.charCodeAt();
    }
    return result;
  }
  while(num >= 10) {
    num = addDigit(num);
  }
  return num;
};
let num = 38;
console.log(addDigits(num));
num = 0;
console.log(addDigits(num));
